def prost(x):
    if x<=1:
        return False
    for i in range(2,int(x**0.5)+1):
        if (x%i)==0:
            return False
    return True


n = input() 
if n[0] == '0' or len(n) != 4 or not n.isdigit(): 
    print(0) 
else:
    max_prost = 0
    for i in range(4):
        for j in range(i+1,5):
            n_i = int(n[i:j])
            if prost(n_i) and max_prost < n_i:
                    max_prost = n_i
    print(max_prost)
